const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
// 设置静态资源目录
app.use(express.static(__dirname + '/public'))

// 以 /api开头的请求，都转发到目标服务器 http://localhost:8080去
app.use('/api',
    createProxyMiddleware({
        target: 'http://localhost:8080',
        pathRewrite:{
            '^/api':'' // 重写路径去掉 /api
        },
        changeOrigin: true
    }));
app.listen(3000);